/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */
package es.silenus.detecta.model;

/**
 * A question in a survey form definition. Persistent, read-write.
 *
 * @author <a href="mailto:malonso@silenus-consultoria.es">Mariano Alonso</a>
 *
 * @since 22-mar-2009 11:04:04
 */
public class Question implements java.io.Serializable {
	/**
	 * The identifier.
	 */
	private long id;

	/**
	 * The code, must be unique.
	 */
	private String code;

	/**
	 * The description.
	 */
	private String description;

	/**
	 * The survey.
	 */
	private Survey survey;

	/**
	 * The knowledge unit.
	 */
	private KnowledgeUnit unit;

/**
   * Constructor.
   */
	public Question() {
	}

	/**
	 * Retrieves the identifier.
	 *
	 * @return the identifier.
	 */
	public long getId() {
		return this.id;
	}

	/**
	 * Sets the identifier.
	 *
	 * @param id the identifier.
	 */
	public void setId(long id) {
		this.id = id;
	}

	/**
	 * Retrieves the code.
	 *
	 * @return the code.
	 */
	public String getCode() {
		return this.code;
	}

	/**
	 * Sets the code.
	 *
	 * @param code the code.
	 */
	public void setCode(final String code) {
		this.code = code;
	}

	/**
	 * Retrieves the description.
	 *
	 * @return the description.
	 */
	public String getDescription() {
		return this.description;
	}

	/**
	 * Sets the description.
	 *
	 * @param description the description.
	 */
	public void setDescription(final String description) {
		this.description = description;
	}

	/**
	 * Retrieves the survey.
	 *
	 * @return the survey.
	 */
	public Survey getSurvey() {
		return this.survey;
	}

	/**
	 * Sets the survey.
	 *
	 * @param survey the survey.
	 */
	public void setSurvey(final Survey survey) {
		this.survey = survey;
	}

	/**
	 * Retrieves the knowledge unit.
	 *
	 * @return the knowledge unit.
	 */
	public KnowledgeUnit getUnit() {
		return unit;
	}

	/**
	 * Sets the knowledge unit.
	 *
	 * @param unit the knowledge unit.
	 */
	public void setUnit(final KnowledgeUnit unit) {
		this.unit = unit;
	}

	/**
	 * Checks if objects are equal.
	 *
	 * @param o other object.
	 *
	 * @return true if equal, false otherwise.
	 */
	@Override
	public boolean equals(Object o) {
		if(this == o) {
			return true;
		}

		if(!(o instanceof Question)) {
			return false;
		}

		Question question = (Question)o;

		if(getId() != question.getId()) {
			return false;
		}

		return true;
	}

	/**
	 * Calculates the hash of this instance.
	 *
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		return (int)(getId() ^ (getId() >>> 32));
	}

	/**
	 * Stringifies this instance.
	 *
	 * @return the string representation.
	 */
	@Override
	public String toString() {
		final StringBuilder sb = new StringBuilder();

		sb.append("Question");
		sb.append("{id=").append(getId());
		sb.append(", code='").append(getCode()).append('\'');
		sb.append('}');

		return sb.toString();
	}
}
